

import javax.swing.JSplitPane
import layoutVariety.AlignDirection._
import layoutVariety.Box
import scala.swing.SplitPane
import scala.swing.Orientation
import scala.swing.BoxPanel

package layoutVariety
{
	class UnderConstrainedBox(ref : Int) extends Box(ref)
	{	  	
			// set the JPanel inside the scroll pane
			private var pane = new SplitPane(Orientation.Horizontal); 
			jc.asInstanceOf[BoxPanel].contents += pane;
			
			/* public interface */
			override def setAlignment(alignment : AlignDirection) : Box = 
			{  
			  if (alignment == Hor)
			  {
			    pane.asInstanceOf[SplitPane].orientation = Orientation.Vertical			
			  }
			  else
			  {			    
			    pane.asInstanceOf[SplitPane].orientation = Orientation.Horizontal
			  }
				  
			  return this;
			}
			override def addWidget(child : Widget) = 
			{
			 
			  if(children.length == 0)
			    pane.topComponent = child.getWidget
			  else if (children.length == 1)
		        pane.bottomComponent = child.getWidget
		      else
		      {
		        val temp = new SplitPane(getAlignment)
		        temp.bottomComponent = child.getWidget
		        temp.topComponent = pane;
		        pane = temp;
		      }
			
		      // add the widget to the children list
			  children+=child;
			  
			}
			
			// splitpane orientation behaves the oposite of what we expect...
			private def getAlignment() : Orientation.Value = 
			{
			  if (jc.asInstanceOf[SplitPane].orientation == Orientation.Vertical)
			    Orientation.Horizontal
		      else
		        Orientation.Vertical
			}
			
	}
}